/**
 * <p>Copyright: Copyright (c) 2014</p>
 * <p>Company: ---Technology Co. Ltd</p>
 * <p>2014-5-5</p>
 * @author Jan.Zhang
 */
package com.xianl.busiplat.service.impl;

import java.util.List;
import java.util.Map;
import com.xianl.busiplat.dao.BaseDao;
import com.xianl.busiplat.dwz.Page;
import com.xianl.busiplat.service.BaseService;
import com.xianl.busiplat.util.PlatBeanUtil;


/** 
 * desc:
 * <p>author: Jan.Zhang </p>
 * date: 2014-5-5
 */
public class BaseServiceImpl<T> implements BaseService<T> {

	protected BaseDao<T> mapper;
	
	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#save(java.lang.Object)
	 */
	@Override
	public void save(T entity) {
		mapper.insert(entity);
	}

	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#update(java.lang.Object)
	 */
	@Override
	public void update(T entity) {
		mapper.update(entity);
	}

	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#delete(java.lang.Object)
	 */
	@Override
	public void delete(T entity) {
		mapper.delete(entity);
	}

	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#get(java.lang.Object)
	 */
	@Override
	public T get(T entity) {
		return mapper.selectOne(entity);
	}

	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#findAll()
	 */
	@Override
	public List<T> findAll(T entity) {
		return mapper.findAll(entity);
	}

	/* 
	 * desc:
	 * @see com.umpay.sc.plat.core.service.BaseService#findAll(com.umpay.sc.plat.core.dwz.Page)
	 */
	@Override
	public List<T> findAll(T entity, Page page) {
		Map<String, Object> params = null;
		try {
			params = PlatBeanUtil.getPoValue(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapper.findPage(page, params);
	}

	
	/**
	 * @param mapper the mapper to set
	 */
	public void setMapper(BaseDao<T> mapper) {
		this.mapper = mapper;
	}
}
